package com.weitu.contractor.service.impl;

import com.weitu.contractor.entity.StaffTrain;
import com.weitu.contractor.entity.StaffTrainCriteria;
import com.weitu.contractor.mapper.StaffTrainMapper;
import com.weitu.contractor.service.StaffTrainService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class StaffTrainServiceImpl implements StaffTrainService {
    private final StaffTrainMapper staffTrainMapper;

    private static final Logger logger = LoggerFactory.getLogger(StaffTrainServiceImpl.class);

    @Autowired
    public StaffTrainServiceImpl(StaffTrainMapper staffTrainMapper) {
        this.staffTrainMapper = staffTrainMapper;
    }

    @Override
    public int countByCriteria(StaffTrainCriteria example) {
        int count = this.staffTrainMapper.countByCriteria(example);
        logger.debug("count: {}", count);
        return count;
    }

    @Override
    public StaffTrain selectByPrimaryKey(String id) {
        return this.staffTrainMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<StaffTrain> selectByCriteria(StaffTrainCriteria example) {
        return this.staffTrainMapper.selectByCriteria(example);
    }

    @Override
    @Transactional
    public int deleteByPrimaryKey(String id) {
        return this.staffTrainMapper.deleteByPrimaryKey(id);
    }

    @Override
    @Transactional
    public int updateByPrimaryKeySelective(StaffTrain record) {
        return this.staffTrainMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    @Transactional
    public int updateByCriteriaSelective(StaffTrain record, StaffTrainCriteria example) {
        return this.staffTrainMapper.updateByCriteriaSelective(record, example);
    }

    @Override
    @Transactional
    public int insertSelective(StaffTrain record) {
        return this.staffTrainMapper.insertSelective(record);
    }

    @Override
    public boolean checkIfExistSameName(String name) {
        StaffTrainCriteria criteria = new StaffTrainCriteria();
        criteria.createCriteria()
                .andDelStateEqualTo(0)
                .andNameEqualTo(name);
        return this.staffTrainMapper.countByCriteria(criteria) > 0;
    }

    @Override
    public boolean checkIfExistSameName(String name, String id) {
        StaffTrainCriteria criteria = new StaffTrainCriteria();
        criteria.createCriteria()
                .andDelStateEqualTo(0)
                .andNameEqualTo(name)
                .andIdNotEqualTo(id);
        return this.staffTrainMapper.countByCriteria(criteria) > 0;
    }
}